﻿
///将点数转换成度数
function getArray(data) {

    var len = data.length;
    var array = new Array(len);

    for (var i = 0; i < len; i++) {
        var xValue = 360 / len * (i + 1);
        array[i] = [xValue, data[i]];
    }
    return array;

}

///描一条曲线
function drawSingleSpline(ID) {
    $.ajax({
        url: 'ajax_analysis.ashx',
        type: 'get',
        dataType: 'xml', //这里可以不写，但千万别写text或者html!!! 
        data: { id: ID, field: "HYGGL" },
        timeout: 2000,
        cache: false,
        error: function (xml) {
            alert('数据有错误' + xml);
        },
        success: function (xml) {
            var data1 = [];
            $(xml).find("tables").children().each(function () {
                var l = $(this).children("l").text();
                data1.push(Number(l));
            });

            var chart = $('#container').highcharts();
            chart.addSeries({
                data: getArray(data1),
                color: '#0000AA'
            });

            //   p.attr("title", chart.series.length - 1);
        }
    });
}
var fun;
$(document).ready(fun = function () {
    drawSingleSpline(11284);


    ///描图控件属性设置
    $('#container').highcharts({
        colors: [
                 '#ff7e08',
                 '#fd230a',
                 '#fbbc01',
                 '#9ff0000',
                 '#1afd0e',
                 '#4929f0',
                 '#f28ff3',
                 '#77a1f5',
                 '#c4f505',
                 '#f6c90a'
             ],

        chart: {
            zoomType: 'x',
            type: 'spline',
            marginRight: 5,
            events: {
                load: function () {

                }
            }
        },
        xAxis: {
            max: 360,
            tickInterval: 20
        },

        title: {
            text: '',
            x: -20 //center
        },
        subtitle: {
            text: '',
            x: -20
        },

        yAxis: {
            title: {
                text: ''
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            valueSuffix: ''
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'middle',
            borderWidth: 0
        },
        plotOptions: {

            series: {
                animation: {
                    duration: 10
                }
            },

            spline: {
                lineWidth: 2,
                states: {
                    hover: {
                        lineWidth: 3
                    }
                },
                marker: {
                    enabled: false
                }

            }

        },
        series: []
    });



});
